// $codepro.audit.disable numericLiterals, nullPointerDereference
/**
 * TreatmentScreenUI
 */
package edu.gatech.coc.betameisters.userinterfaces;


import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JEditorPane;

import edu.gatech.coc.betameisters.infoholders.Treatment;
import edu.gatech.coc.betameisters.infoholders.Constants.VisitType;
import edu.gatech.coc.betameisters.main.MainPanel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


/**
 * The Class TreatmentScreenUI.
 * 
 * @author Suren Nihalani
 * @version $REVISION$
 */
@SuppressWarnings("serial")
public class TreatmentScreenUI extends JPanel {

	/** The treatment. */
	private final Treatment theTreatment;

	/** The label treatment. */
	private final JLabel labelTreatment;

	/** The sign it button. */
	private final JButton submitTreatmentButton;

	/** The visit type combo box. */
	private final JComboBox visitTypeComboBox;

	/** The label type. */
	private final JLabel labelType;

	/** The details editor pane. */
	private final JEditorPane detailsEditorPane;

	/** The label details. */
	private final JLabel labelDetails;

	/** The Constant for OFFICE VISIT. */
	private static final String OFFICE_VISIT = "Office Visit";

	/** The Constant for PHONE CONSULT. */
	private static final String PHONE_CONSULT = "Phone consult";

	/** The Constant for ANNUAL_PHYSICAL */
	private static final String ANNUAL_PHY = "Annual Physical";

	/**
	 * 
	 */
	private MainPanel parent;
	
	/**
	 * Create the panel.
	 * 
	 * @param aTreatment
	 *            The Treatment object where changes need to be saved to.
	 */
	public TreatmentScreenUI(Treatment aTreatment, MainPanel p) { // $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.constructorsOnlyInvokeFinalMethods
		theTreatment = aTreatment;
		parent = p;
		final SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);

		labelTreatment = new JLabel("Treatment");
		springLayout.putConstraint(SpringLayout.NORTH, labelTreatment, 10,
				SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, labelTreatment, 121,
				SpringLayout.WEST, this);
		add(labelTreatment);

		submitTreatmentButton = new JButton("Submit");
		submitTreatmentButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (visitTypeComboBox.getSelectedItem().toString()
						.equals(OFFICE_VISIT)) {
					theTreatment.setTreatmentType(VisitType.OFFICEVISIT);
				} else if (visitTypeComboBox.getSelectedItem().toString()
						.equals(PHONE_CONSULT)) {
					theTreatment.setTreatmentType(VisitType.PHONECONSULT);
				} else if (visitTypeComboBox.getSelectedItem().toString()
						.equals(ANNUAL_PHY)) {
					theTreatment
							.setTreatmentType(VisitType.ANNUALPHYSICAL);
				}
				theTreatment.setTreatmentDetails(detailsEditorPane.getText());
				parent.setTreatment(theTreatment);
			}
		});
		springLayout.putConstraint(SpringLayout.SOUTH, submitTreatmentButton, -10,
				SpringLayout.SOUTH, this);
		springLayout.putConstraint(SpringLayout.EAST, submitTreatmentButton, -10,
				SpringLayout.EAST, this);
		add(submitTreatmentButton);

		visitTypeComboBox = new JComboBox();
		springLayout.putConstraint(SpringLayout.NORTH, visitTypeComboBox, 6,
				SpringLayout.SOUTH, labelTreatment);
		springLayout.putConstraint(SpringLayout.WEST, visitTypeComboBox, -2,
				SpringLayout.WEST, labelTreatment);
		springLayout.putConstraint(SpringLayout.EAST, visitTypeComboBox, 0,
				SpringLayout.EAST, submitTreatmentButton);
		visitTypeComboBox.setModel(new DefaultComboBoxModel(new String[] {
				OFFICE_VISIT, PHONE_CONSULT, ANNUAL_PHY }));
		add(visitTypeComboBox);

		labelType = new JLabel("Type:");
		springLayout.putConstraint(SpringLayout.NORTH, labelType, 5,
				SpringLayout.NORTH, visitTypeComboBox);
		springLayout.putConstraint(SpringLayout.EAST, labelType, -6,
				SpringLayout.WEST, visitTypeComboBox);
		add(labelType);

		detailsEditorPane = new JEditorPane();
		springLayout.putConstraint(SpringLayout.NORTH, detailsEditorPane, -93,
				SpringLayout.NORTH, submitTreatmentButton);
		springLayout.putConstraint(SpringLayout.WEST, detailsEditorPane, 10,
				SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, detailsEditorPane, -6,
				SpringLayout.NORTH, submitTreatmentButton);
		springLayout.putConstraint(SpringLayout.EAST, detailsEditorPane, 0,
				SpringLayout.EAST, submitTreatmentButton);
		add(detailsEditorPane);

		labelDetails = new JLabel("Details: ");
		springLayout.putConstraint(SpringLayout.WEST, labelDetails, 0,
				SpringLayout.WEST, detailsEditorPane);
		springLayout.putConstraint(SpringLayout.SOUTH, labelDetails, -6,
				SpringLayout.NORTH, detailsEditorPane);
		add(labelDetails);

	}
}
